package com.open.ssm.jasypt;

import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.StandardPBEByteEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自定义的加密器配置类
 *
 * @version: v1.0.0
 * @author: wangpf
 * @date: 2020年4月3日 下午6:01:13
 */
@Configuration
public class CodeSheepEncryptorCfg {
	
	@Bean(name = "codeSheepEncryptorBean" )
    public StringEncryptor codesheepStringEncryptor() {
        PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
        SimpleStringPBEConfig config = new SimpleStringPBEConfig();
        // 加密密钥
        config.setPassword("openssm2021");
        // 加密算法
        //config.setAlgorithm("PBEWITHHMACSHA512ANDAES_256");
        config.setAlgorithm(StandardPBEByteEncryptor.DEFAULT_ALGORITHM);
        config.setKeyObtentionIterations("1000");
        config.setPoolSize("1");
        config.setProviderName("SunJCE");
        config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
        config.setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator");
        config.setStringOutputType("base64");
        encryptor.setConfig(config);
        
        return encryptor;
    }
}
